<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <!-- <script src="http://127.0.0.1:2000/list"></script> -->
</head>

<body>
  <input type='button' id="btn" value="jsonp" />
  <script>
    const btn = document.querySelector('#btn')
    function fn (res) {
      console.log(res, 7774444);
    }
    btn.onclick = function () {
      console.log(111222);
      // fetch('http://127.0.0.1:2000/list').then(response => {
      //   return response.text()
      // }).then(result => {
      //   console.log(result, 888);
      // })
      /* 利用script的src特性不会产生跨域请求
      1-动态创建script标签
      2-动态追加script标签元素到dom中
      */
      let script = document.createElement('script')
      script.src = 'http://127.0.0.1:2000/list?callback=fn'
      // console.log(script, 999);
      document.body.appendChild(script)
    }
  </script>
</body>

</html>